package com.clf.springCloudTest.dao;

import com.clf.test.Country;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Author: chenglongfei
 * @date: 2022/7/14
 * @Description CountryDao
 */
@Repository
@Mapper
public interface CountryDao {

    @Select("select * from test_country where country_id = #{countryId}")
    @Results(id = "countryResults", value = {
            @Result(property="countryId", column = "country_id"),
            @Result(property = "cities",
                    column = "country_id",
                    javaType = List.class,
                    many = @Many(select = "com.sfac.springCloudTest.dao.CityDao.getCitiesByCountryId"))
    })
    Country getCountryByCountryId(int countryId);

    @Select("select * from test_country where country_name = #{countryName} limit 1")
    @ResultMap(value={"countryResults"})
    Country getCountryByCountryName(String countryName);
}
